package com.ponhu.ea2.stockcenter.provider.service.biz.stockwarehouse;

import com.ponhu.ea2.stockcenter.dto.WMSEventInfoDTO;
import com.ponhu.ea2.stockcenter.enums.ExchangeActionTypeEnum;
import com.ponhu.ea2.stockcenter.provider.service.entity.StockInventoryRealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.ponhu.ea2.stockcenter.enums.ExchangeActionTypeEnum.*;

/**
 * 销退入库、盘盈入库、采购入库、调拨入库、其他入库、调拨计划入库
 */
@Component
public class CommonInHandler extends AbsCoreHandler {

    public CommonInHandler() {
        inOccupy = true;
        operateWarehouse = true; // 当前操作仓库是 inWarehouseCode
        whActionTypeArr = new ExchangeActionTypeEnum[]{
                TRANSFER_PLAN_IN,
                SALES_RETURN_IN,
                CHECK_PROFIT_IN,
                PURCHASE_IN,
                TRANSFER_IN,
                OTHER_IN
        };
    }

    @Override
    protected void absHandle(WMSEventInfoDTO eventInfoDTO) {

        if (eventInfoDTO.getActionType() != TRANSFER_IN) {
            // 任务链路中的仓库库存变动预校验
            preTraceCheck(eventInfoDTO);
        }

        // 仓库库存变动数据库操作
        stockWarehouseHandle(eventInfoDTO);

        // 仓库库存变动对销售库存影响
        salesStockHandle(eventInfoDTO);

        // 修改货品在途库存数量
        if (eventInfoDTO.getActionType() == TRANSFER_PLAN_IN)
            updateFreeStockNum(eventInfoDTO);
    }

}
